# -*- coding: utf-8 -*-
from django.db.models import Q
from rest_framework import serializers

from app.emergency.models import PlanOutpersion
from dvadmin.utils.json_response import SuccessResponse
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.viewset import CustomModelViewSet


class PlanOutpersionSerializer(CustomModelSerializer):
    """
    预案外部人员-序列化器
    """
    plan_name = serializers.CharField(source='plan.name', read_only=True)
    class Meta:
        model = PlanOutpersion
        fields = "__all__"
        read_only_fields = ["id"]


class PlanOutpersionCreateUpdateSerializer(CustomModelSerializer):
    """
    操作预案外部人员  创建/更新时的列化器
    """

    class Meta:
        model = PlanOutpersion
        fields = '__all__'


class PlanOutpersionViewSet(CustomModelViewSet):
    """
    预案外部人员接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = PlanOutpersion.objects.order_by('-create_datetime')
    serializer_class = PlanOutpersionSerializer


